package www.openteam.com.model;

import android.support.annotation.Nullable;

import www.openteam.com.OTApplication;
import www.openteam.com.base.BaseModel;
import www.openteam.com.bean.AppAuthority;
import www.openteam.com.exception.ApiException;
import www.openteam.com.subscribe.CommonSubscriber;
import www.openteam.com.transformer.CommonTransformer;

/**
 * Created by kylin on 2017/3/21.
 */

public class FAuthorityModel extends BaseModel {

    private boolean isAuthority=false;

    public  boolean checkAuthority(@Nullable String aCode, @Nullable int uId ,@Nullable final FAuthorityOnListener fAuthorityOnListener){

        if (fAuthorityOnListener ==null) {
            throw new RuntimeException("InfoHint不能为空");
        }
            httpApiService.checkAuthority(aCode,uId)
                    .compose(new CommonTransformer<AppAuthority>())
                    .subscribe(new CommonSubscriber<AppAuthority>(OTApplication.getmContext()) {
                        @Override
                        public void onNext(AppAuthority appAuthority) {
                                isAuthority=true;
                            fAuthorityOnListener.successInfo(appAuthority);
                        }

                        @Override
                        protected void onError(ApiException e) {
                            super.onError(e);

                            isAuthority=false;
                             fAuthorityOnListener.failInfo(e.message);
                        }

                    });

        return isAuthority;
    }

    public interface  FAuthorityOnListener{

        void successInfo(AppAuthority appAuthority);

        void failInfo(String str);

    }

}
